package frontend.lexer.token;

import java.util.ArrayList;

public class StrConToken extends Token {
    private final String stringVal;
    private final ArrayList<StrConItem> strConItems;
    private final int placeHolderCnt;

    public StrConToken(TokenType tokenType, String tokenString, String stringVal, ArrayList<StrConItem> strConItems, int lineNum, String line, int linePosStart, int linePosEnd) {
        super(tokenType, tokenString, lineNum, line, linePosStart, linePosEnd);
        this.stringVal = stringVal;
        this.strConItems = strConItems;
        int placeHolderCnt = 0;
        for (StrConItem strConItem: strConItems) {
            if (strConItem instanceof PlaceHolderItem) {
                placeHolderCnt++;
            }
        }
        this.placeHolderCnt = placeHolderCnt;
    }

    public String getStringVal() {
        return stringVal;
    }

    public int getPlaceHolderCnt() {
        return placeHolderCnt;
    }

    public abstract static class StrConItem {
        public abstract StrConItemType getType();
    }
    public enum StrConItemType {
        CHAR, STR, PLACEHOLDER
    }
    public static class CharItem extends StrConItem {
        private final char charVal;
        public CharItem(char charVal) {
            this.charVal = charVal;
        }
        public char getCharVal() {
            return charVal;
        }

        @Override
        public StrConItemType getType() {
            return StrConItemType.CHAR;
        }
    }
    public static class StrItem extends StrConItem {
        private final String strVal;
        public StrItem(String strVal) {
            this.strVal = strVal;
        }
        public String getStrVal() {
            return strVal;
        }

        @Override
        public StrConItemType getType() {
            return StrConItemType.STR;
        }
    }
    public static class PlaceHolderItem extends StrConItem {
        private final String placeHolder;
        public PlaceHolderItem(String placeHolder) {
            this.placeHolder = placeHolder;
        }
        public String getPlaceHolder() {
            return placeHolder;
        }

        @Override
        public StrConItemType getType() {
            return StrConItemType.PLACEHOLDER;
        }
    }

    public ArrayList<StrConItem> getStrConItems() {
        return strConItems;
    }
}
